home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TestMoreInterfaceLib.c
-
- Contains: Test rig for MoreInterfaceLib.
-
- Written by: Quinn
-
- Copyright: Copyright © 1999 by Apple Computer, Inc., all rights reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
-
- <3> 16/9/99 Quinn Add real code to test the FSM FCB accessors.
- <2> 15/6/99 Quinn Link with the Extended Disk Init Package routines, just to test
- their linkage.
- <1> 20/4/99 Quinn First checked in.
- */
-
- /////////////////////////////////////////////////////////////////
- // MoreIsBetter Setup
-
- #include "MoreSetup.h"
-
- /////////////////////////////////////////////////////////////////
- // Mac OS Interfaces
-
- #include <MacTypes.h>
- #include <Devices.h>
- #include <Gestalt.h>
- #include <TextUtils.h>
-
- /////////////////////////////////////////////////////////////////
- // ANSI C Interfaces
-
- #include <stdio.h>
-
- /////////////////////////////////////////////////////////////////
- // MIB Interfaces
-
- #include "MoreInterfaceLib.h"
-
- /////////////////////////////////////////////////////////////////
-
- static void DoTestGestaltValue(void)
- {
- OSStatus err;
- SInt32 tmp;
-
- err = MoreNewGestaltValue('Foo!', 666);
- if (err == noErr) {
- err = Gestalt('Foo!', &tmp);
- if (err == noErr && tmp != 666) {
- err = -1;
- }
- }
- if (err == noErr) {
- err = MoreReplaceGestaltValue('Foo!', 667);
- if (err == noErr) {
- err = Gestalt('Foo!', &tmp);
- if (err == noErr && tmp != 667) {
- err = -2;
- }
- }
- }
- if (err == noErr) {
- err = MoreSetGestaltValue ('Foo!', 668);
- if (err == noErr) {
- err = Gestalt('Foo!', &tmp);
- if (err == noErr && tmp != 668) {
- err = -2;
- }
- }
- }
- if (err == noErr) {
- err = MoreDeleteGestaltValue('Foo!');
- if (err == noErr) {
- if ( Gestalt('Foo!', &tmp) == noErr) {
- err = -3;
- }
- }
- }
-
- if (err == noErr) {
- printf("Success!\n");
- } else {
- printf("Failed with error %ld.\n", err);
- }
- }
-
- /////////////////////////////////////////////////////////////////
-
- static void DoTestExtendedDiskInit(Boolean mustBeFalse)
- {
- printf("The purpose of this test is simple to test the linkage.\n");
- if (mustBeFalse) {
- OSStatus err;
-
- err = MoreDIXFormat(1, false, 0, nil);
- err = MoreDIXZero(1, nil, 0, 0, 0, 0, nil);
- err = MoreDIReformat(1, 0, nil, nil);
- }
- }
-
- /////////////////////////////////////////////////////////////////
-
- static void DoTestFSM()
- {
- // MoreUTFindDrive
- {
- SInt16 firstDriveNum;
- DrvQElPtr foundDrive;
-
- firstDriveNum = ((DrvQElPtr) GetDrvQHdr()->qHead)->dQDrive;
-
- if ( MoreUTFindDrive(firstDriveNum, &foundDrive) != noErr ||
- foundDrive->dQDrive != firstDriveNum) {
- printf("•••MoreUTFindDrive failed.\n");
- }
- }
-
- // MoreUTLocateFCB
- {
- VCBPtr firstVCB;
- SInt16 foundRefNum;
- FCBRecPtr foundFCB;
- OSStatus junk;
- OSStatus err;
- UInt32 sysVersion;
-
- // We're assuming that the boot volume is first in the VCB,
- // that the system file is named "System", and that it's
- // file reference number is 2. All of this is not guaranteed
- // to be true, but it's good enough for this test tool..
-
- firstVCB = ((VCBPtr) GetVCBQHdr()->qHead);
- if ( MoreUTLocateFCB(firstVCB, 0, "\pSystem", &foundRefNum, &foundFCB) == noErr
- && foundRefNum == 2
- && EqualString(foundFCB->fcbCName, "\pSystem", false, true)) {
-
- // Get system version.
-
- junk = Gestalt(gestaltSystemVersion, (SInt32 *) &sysVersion);
- MoreAssertQ(junk == noErr);
-
- // We now search for the second file called' "System". We
- // find it on Mac OS 8.5 and later (because the data fork
- // of the System file is open) but not on Mac OS 8.1 or earlier.
-
- err = MoreUTLocateNextFCB(firstVCB, 0, "\pSystem", &foundRefNum, &foundFCB);
- if ( err == noErr && sysVersion < 0x0850
- || err != noErr && sysVersion >= 0x0850 ) {
- printf("•••MoreUTLocateNextFCB failed.\n");
- }
- } else {
- printf("•••MoreUTLocateFCB failed.\n");
- }
- }
-
- // MoreUTIndexFCB
- {
- OSErr err;
- Boolean found;
- VCBPtr firstVCB;
- SInt16 foundRefNum;
- FCBRecPtr foundFCB;
-
- firstVCB = ((VCBPtr) GetVCBQHdr()->qHead);
- found = false;
- foundRefNum = 0;
- do {
- err = MoreUTIndexFCB(firstVCB, &foundRefNum, &foundFCB);
- if (err == noErr) {
- found = EqualString(foundFCB->fcbCName, "\pSystem", false, true);
- }
- } while ( err == noErr && ! found );
- if ( ! found ) {
- printf("•••MoreUTIndexFCB failed.\n");
- }
- }
-
- // MoreUTResolveFCB
- {
- FCBRecPtr foundFCB;
-
- if ( MoreUTResolveFCB(2, &foundFCB) != noErr || ! EqualString(foundFCB->fcbCName, "\pSystem", false, true)) {
- printf("•••MoreUTResolveFCB failed.\n");
- }
- }
-
- printf("FSM test done.\n");
- }
-
- /////////////////////////////////////////////////////////////////
-
- void main(void)
- {
- char commandStr[256];
-
- printf("Hello Cruel World!\n");
- printf("TestMoreInterfaceLib\n");
- printf("-- A simple test program for the MoreInterfaceLib library.\n");
-
- printf("What test would you like to run?\n");
- printf("a) Gestalt Value\n");
- printf("X) Extended Disk Init\n");
- printf("f) FSM test\n");
- printf("Enter a command:\n");
- gets(commandStr);
- switch (commandStr[0]) {
- case 'a':
- DoTestGestaltValue();
- break;
- case 'X':
- DoTestExtendedDiskInit(false);
- break;
- case 'f':
- DoTestFSM();
- break;
- default:
- printf("Huh?\n");
- break;
- }
-
- printf("Done. Press Q to Quit.\n");
- }
-